import { Component } from '@angular/core';
import { Plugins } from '@capacitor/core';

import { ElectronService } from 'ngx-electron';

const { LocalNotifications, Clipboard, Modals } = Plugins;

@Component({
    selector: 'app-home',
    templateUrl: 'home.page.html',
    styleUrls: ['home.page.scss'],
})
export class HomePage {
    someText = '一段文字，用于演示';
    imgUrl = "assets/coder-512.png";

    constructor(private electronService: ElectronService) {
        if (this.electronService.isElectronApp) {
            console.log('这是一个Electron的应用。');
            this.electronService.ipcRenderer.on('trigger-alert', this.showElectronAlert);
        }
    }

    async showElectronAlert() {
        Modals.alert({
            title: '你好！',
            message: '这是来自菜单的消息 :)',
            buttonTitle: '知道了'
        });
    }

    async scheduleNotification() {
        LocalNotifications.schedule({
            notifications: [
                {
                    title: '测试通知 - 1',
                    body: '测试通知 - 1 的内容',
                    id: 1,
                    schedule: { at: new Date(Date.now() + 1000 * 5) },
                    sound: 'assets/beep-03.wav',
                    attachments: null,
                    actionTypeId: '',
                    extra: null
                },
                {
                    title: '测试通知 - 2',
                    body: '测试通知 - 2 的内容',
                    id: 2,
                    schedule: { at: new Date(Date.now() + 1000 * 5 * 2) },
                    sound: 'assets/beep-03.wav',
                    attachments: null,
                    actionTypeId: '',
                    extra: null
                }

            ]
        });
    }

    async copyText() {
        Clipboard.write({
            string: this.someText
        });

        Modals.alert({
            title: 'Ok',
            message: 'Text is in your clipboard.'
        });
    }
}
